package com.yunhe.day322.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunhe.day322.domain.Permission;
import com.yunhe.day322.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private PermissionService perService;
    /**
     * 查询所有
     * @param page
     * @param size
     * @param model
     * @return
     */
    @RequestMapping("findAll")
    public String findAll(@RequestParam(value = "page", defaultValue = "1") Integer page , @RequestParam(value = "size",defaultValue = "5") Integer size, Model model){
        PageHelper.startPage(page,size);

        List<Permission> list = perService.findAll();

        PageInfo pageInfo = new PageInfo(list);

        model.addAttribute("pageInfo",pageInfo);

        return "permission-list";

    }
    @RequestMapping("save")
    public String save(Permission permission){
        perService.save(permission);

        return "redirect:findAll";
    }
    /**
     * 删除角色
     * @param id
     * @return
     */
    @RequestMapping("deletePermission")
    public String deletePermission(int id){
        perService.deleteRole(id);
        return "redirect:findAll";
    }

}
